package com.csx.set;

import com.csx.linkedlist.LinkedList;

/**
 * 基于链表的集合
 * @param <E>
 */
public class  LinkedListSet<E> implements Set<E> {

    private LinkedList<E> list;

    public LinkedListSet(){
        list = new LinkedList<>();
    }

    @Override
    public void add(E e) {
        if (!list.contains(e)){
            list.addFirst(e);
        }
    }

    @Override
    public void remove(E e) {
        list.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    public static void main(String[] args) {
        LinkedListSet<Integer> linkedListSet = new LinkedListSet<>();
        for (int i = 0; i < 5; i++) {
            linkedListSet.add(i);
        }
        linkedListSet.remove(1);
        boolean contains = linkedListSet.contains(1);
        linkedListSet.add(1);
    }
}
